package edu.sctu.zhuyingzhi.rankMethod;


/**
 * Created by user24 on 2015/5/18.
 */
public class InsertRank {

    private  int[] insertSort(int[]arr){
        if(arr == null || arr.length < 2){
            return arr;
        }
        for(int i=1;i<arr.length;i++){
            for(int j=i;j>0;j--){
                if(arr[j]<arr[j-1]){
//TODO:
                    int temp=arr[j];
                    arr[j]=arr[j-1];
                    arr[j-1]=temp;
                }else{
//接下来是无用功
                    break;
                }
            }
        }
        return arr;
    }
    public static void main(String[] args) {
        int[] arr = new int[10];
        int[] arr1;
        for (int i = 0; i < 10; i++) {
            arr[i] = (int) (Math.random()*100);
            System.out.println(arr[i]);
        }

        arr1= new InsertRank().insertSort(arr);
        for (int i = 0; i < 10; i++) {
            System.out.println(arr1[i]);
        }
    }
}
